XN.namespace('ui');
//XN.debug.on();
XN.ui.miniEditor = function(p)
{
    $extend(this,p);
    this.getEmoList();
}

XN.ui.miniEditor.prototype = $extend({},XN.ui.element);

$extend(XN.ui.miniEditor.prototype,{
    _emoRendered:false,//表情渲染完成标示
    IDofEditor:'miniEditor',
    IDofForm:'miniEditorForm',
    IDofAction:'miniEditorAction',
    IDofEmoHolder:'miniEditorEmoHolder',
    IDofEmoHeader:'miniEditorEmoTabHolder',
    IDofEmoTab:'miniEditorEmoTab',
    IDofEmoList:'miniEditorEmoList',
    IDofTextarea:'miniEditorTextarea',
    IDofNotVipTip:'notVipTip',
	IDofUploadBtn:'addPhotoBtn',
    emoList:'',
    _emoList:null,
    ubbPrefix:'',
    ubbSuffix:'',
    _inputPos:{"start":0, "end":0, "item": [0, 0]},
    allowAddLink:true,
    allowAddPhoto:false,
    isVip:false,
    emoAlignType:'3-2',
    emoOffsetX:0,
    emoOffsetY:-1,
    emoType:0,
    _emoKind://表情组在此定义
    {
        '0':{name:'默认表情'},
        '1':{name:'阿狸'},
        '2':{name:'囧囧熊'}
    },
    
    //获取表情ubb列表,获取成功后初始化miniEditor
    getEmoList:function()
    {
        var This = this,
            url = 'http://status.' + XN.env.domain + '/getubblist.do?type=' + this.emoType;
        new XN.net.xmlhttp({
    		url:url,
            method:'GET',
    		onSuccess:function(r){
                This.emoList = r.responseText;
                XN.log(This.emoList);
                window.setTimeout(function()
                {
                    This.init();
                },0);
            },
    		onError:XN.func.empty
    	});
    },

    //初始化
    init:function()
    {
        var This = this;
        if( !$( this.IDofAction) || !$( this.IDofEmoHolder ) ) return;

        this.initAction();
        this.renderEmotion();
		try{
			this.renderUploadPhoto();
		}catch(e){}//这个try/catch是为了防止读取location的信息的时候在某些情况下(IE6下, 某些在本文件之前加载的文件出错)出现"没有权限"的错误  added by auscar 2009-11-30
		
        

        //keyup记录输入框光标位置
        XN.event.addEvent($(this.IDofTextarea),'keyup',function()
            {
                This.getInputPos();
            }
        )
        //mouseup记录输入框光标位置
        XN.event.addEvent($(this.IDofTextarea),'mouseup',function()
            {
                This.getInputPos();
            }
        )

        //mouseup记录输入框光标位置
		
        //XN.event.addEvent($(this.IDofTextarea),'blur',function()
        //    {
        ////        This.getInputPos();
        //    }
        //)

        //focus记录输入框光标位置
        XN.event.addEvent($(this.IDofTextarea),'focus',function()
            {
                //由于chrome的一个未知bug，在投票下会有取不到光标的问题，用setTimeout此法解决
                setTimeout(function(){ This.getInputPos()}, 10); 
            }
        );

		XN.dom.ready(function(){
			 This.getInputPos();
		});

        if($('emoBtn'))
        {
            //表情菜单按钮click事件绑定
            XN.event.addEvent($('emoBtn'),'click',function(e)
                {
                    XN.event.stop(e || window.event);
                    if(!This._emoRendered){
                        This.renderEmotion();
                    }
                    This.showEmotion();
                }
            )
            
            //表情click事件绑定
            XN.event.addEvent($(this.IDofEmoHolder),'click',function(e)
                {
                    var e = e || window.event;
                    if(e.ctrlKey) XN.event.stop(e);//ctrlKey时表情层不消失
                    This.parseEmotion(e);
                }
            )
            //单击页面空白处隐藏表情
            XN.event.addEvent(document,'click',function(e)
                {
                    This.hideEmotion(e);
                }
            )
            //表情预览事件绑定
            XN.event.addEvent($(this.IDofEmoHolder),'mouseover',function(e)
                {
                    XN.event.stop(e || window.event);
                    This.previewEmotion(e);
                }
            )
            //表情预览关闭事件绑定
            XN.event.addEvent($(this.IDofEmoHolder),'mouseout',function(e)
                {
                    This.hidePreviewEmotion(e);
                }
            )
        }
        //添加链接事件
        if($('addLinkBtn'))
        {
            XN.event.addEvent($('addLinkBtn'),'click',function(e)
                {
                    XN.event.stop(e || window.event);
                    This.showAddLinkFlyer();
                }
            )
		}

        // ------------------------------ 添加一个新的按钮 ---------------------------------------//
        //初始化颜色选择
        colorP = {
            '重置' : '#000000',
            '红色' : '#FF0000',
            '黄色' : '#FFB900',
            '棕色' : '#930004',
            '蓝色' : '#00A5FF',
            '绿色' : '#11BB22',
            '紫色' : '#9500FF',
            '粉红色' : '#FF00C0'
        }

        if( this.showPicker ){
            this.addAction({
                strBtn : '<a href="#" onfocus="this.blur()" id="colorBtn" class="m-editor-color '+ this.pickerDisableClass +'">颜色</a>',
                strPanel : '<div id="colorPanel" class="m-editor-color-palette clearfix">' + this.makePicker( colorP ) + '</div>',
                IDofAction : 'colorBtn',
                IDofPanel : 'colorPanel',
                onAfterAdd : function(){
                    this.getColor = function(){
                        return this.color;
                    }    
                    this.colorReset = function(){
                        this.color = '';
                        $(This.IDofTextarea).style.color = '';
                    } 
                },
                onBtnClick : function(e){
                    var obj = e.srcElement || e.target;
                    if( !This.enablePicker ){//如果color picker是不能用的, 展示特权提示
                        XN.DO.alert({
                            title : '特权提示',
                            msg : XN.ui.miniEditor.colorTip,
                            params : {
                                showCloseButton : true
                            }
                        }).footer.hide();
                        return false;
                    }
                },
                onPanelClick : function(e){
                    var obj = e.srcElement || e.target;
                    var _color = obj.getAttribute('xn_color');
                    if( _color ){
                        //console.log( _color );
                        var t = $(This.IDofTextarea);
                        t.style.color = _color=='#000000'?'':_color;//黑色的话, 就是是当前css主题默认的颜色, 而不是真正的黑色
                        this.color = _color=='#000000'?'':_color;//黑色的话, 就是是当前css主题默认的颜色, 而不是真正的黑色
                        XN.form.help(t).focus();
                    }
                }
            });//end addAction
        }
        //----------------------------------------------------------------------------------------//
       

        if( this.initCallBack ){
            this.initCallBack.call(this);
        }
        XN.log('miniEditor inited');
    },
    //初始化编辑器按钮
    initAction:function()
    {
        if(this.allowAddLink) 
            $(this.IDofAction).appendHTML('<a href="###" id="addLinkBtn" class="m-editor-addlink">链接</a>');
		if (this.allowAddPhoto)
			$(this.IDofAction).appendHTML('<span href="###" class="m-editor-photo"><span id="'+this.IDofUploadBtn+'"></span><span id="miniEditorPhotoInfo"></span><a id="miniEditorDeletePhoto" href="#nogo" class="delete" style="display:none">删除</a></span>')
        $(this.IDofAction).appendHTML('<a href="###" id="emoBtn" class="m-editor-emo">表情</a>');
    },


    // -------------------- added by huihua.lin@opi-corp.com 2010-4-29 -----------------------------//
    addAction : function(obj){
        var This = this;
        if( this.IDofAction  ){
            $( this.IDofAction ).appendHTML( obj.strBtn );
            this.addActionPanel( obj.strPanel );
        }
        var btn = $( obj.IDofAction );
        var panel = $( obj.IDofPanel );
        if( !(btn && panel) )return;
       
        panel.hide();

        btn.addEvent( 'click', function(e){
            e = e || window.event 
            XN.event.stop(e); 
            var ret = obj.onBtnClick.call( This, e ); 
            if( ret === false ){
                return;
            }
            panel.show();             
        });
        XN.event.addEvent( document, 'click', function(){
            panel.hide();        
        });
        panel.addEvent( 'click', function(e){
            e = e || window.event;
            obj.onPanelClick.call( This, e ); 
            XN.event.stop( e ); 
        });
        
       if( obj.onAfterAdd ){
            obj.onAfterAdd.call( This );
       } 
    }, 
    addActionPanel : function( content ){
        var t = $( this.IDofForm ); 
        if( t ){
            t.appendHTML( content ); 
        } 
    },
    makePicker : function(p){
        var html = [];
        html.push(
            '<ul id="miniEditor_picker">'        
        );
        for( var name in p ){

            html.push(
                //'<li><a href="#" style="backgroud-color:', p[name] ,';" title="', name ,'"></a></li>'        
                '<li><a href="#" xn_color="', p[name] ,'" style="background:', p[name] ,'" title="', name ,'"><span xn_color="', p[name] ,'"></span></a></li>'        
            );
        } 
        html.push( '</ul>' );
        return html.join(''); 
    },


    // ---------------------------------------------------------------------------------------------//

    //显示表情弹层
    showEmotion:function()
    {
        XN.log('show emotion');
        var This = this;
        if(!this._emoClicked)
        {
            setTimeout(function()
                {
                    $(This.IDofEmoList).innerHTML = $(This.IDofEmoList).innerHTML.replace(/emosrc/g,'src');
                },0
            );

            this._emoClicked = true;
        }
        this._emoHolder.show();
    },
    
    //隐藏表情弹层
    hideEmotion:function()
    {
        XN.log('hide emotion');
        if(this._previewHolder) this._previewHolder.hide();
        if(this._emoHolder) this._emoHolder.hide();
    },
    
    //初始化表情弹层,根据json加载表情
    renderEmotion:function()
    {
        if(!this.emoList)//未正常获取表情json时隐藏表情按钮
        {
            $('emoBtn').hide();
            return;
        }
        var emo = this._emoList = XN.json.parse(this.emoList).ubbList;
        var list = {}, html = {}, tab = {}, tabImg = '', _preview = '', _forvip = '', tabHtml = '', _emoGroupCount = 0, _emoTabShow = [];
        //遍历表情分组,获取分组名称
        for(var p in this._emoKind)
        {
            list[p] = [];
            html[p] = '';
            tab[p] = this._emoKind[p].name;
            //XN.log(tab[p]);
        }
        
        //向各分组添加表情
        for(var i=0;i<emo.length;i++)
        {
		if( !list[ emo[i].kind] )continue;// 在某些需求下, 可能不会将所有的表情都显示出来, 于是可能出现list[ emo[i].kind ]为空的情况
            var _ie6patch = '';
            if(XN.browser.IE6) _ie6patch = ' onmouseover=\'this.style.borderColor="#808080"\' onmouseout=\'this.style.borderColor="#B8D4E8"\'';
            if(emo[i].size == 2) _preview = ' preview="true" ';
            if(emo[i].kind == 1 || emo[i].kind == 2) _forvip = ' forvip="true" ';
            else _forvip = ' forvip="false" ';

            list[emo[i].kind].push('<li title="' + emo[i].alt + '" ' + _ie6patch + '><img emosrc="http://a.xnimg.cn/' + emo[i].src +'" alt="' + emo[i].alt +'" emotion="' + emo[i].ubb +'"' + _preview + _forvip +' /></li>')
        }

        var _show = "style=\"display:block\"";
        //完成各个分组表情列表
        for(var p in list)
        {
            if(list[p].length > 0)
            {
                html[p] = '<ul class="emo-list" ' + _show + ' id="emoList' + p + '">'
                html[p] += list[p].join('');
                html[p] += '</ul>';
                $(this.IDofEmoList).appendHTML(html[p]);
                //if(p == 1 || p == 2) tabImg = '<img src="' + XN.env.staticRoot + 'imgpro/minieditor/viptabbg.png" align="top" title="VIP专用" />';
                $(this.IDofEmoTab).appendHTML('<li id="emoTab' + p + '"><a href="###" onfocus="this.blur()">' + '&nbsp;' + tab[p] + '&nbsp;' + tabImg +'</a></li>');
                
                _emoGroupCount++;
                _emoTabShow.push(p);
                //XN.log(_emoGroupCount);
                _show = "style=\"display:none\"";
            }
        }
        
        //判断是否显示表情tab
        if(_emoGroupCount > 1)
        {
            var This = this;
            $(this.IDofEmoHeader).show();
            
            var tv = new XN.ui.tabView(
            {
                activeClass : 'current'
            });
            
            for(var i=0;i<_emoTabShow.length;i++)
            {
                tv.addTab(
                {
                    label : 'emoTab' + _emoTabShow[i],
                    active : ( i == 0 ),
                    onActive : (function( i )
                    {
                        return function()
                        {
                            var _ct = tv.getCurrentTab().label.id || tv.getCurrentTab().label;
                            $(_ct.replace('emoTab','emoList')).hide();
                            $('emoList' + _emoTabShow[i]).show();
                            if(This._previewHolder) This._previewHolder.hide();
                            This.hideNotVip();
                        }
                    })( i )
                });
            }
        }
        
        var _emo = {
            alignWith : this.IDofTextarea,
            tagName : 'div',
            alignType : this.emoAlignType,
            offsetX : this.emoOffsetX,
            offsetY : this.emoOffsetY
        }
        
        //表情弹层实例
        this._emoHolder = new XN.ui.fixPositionElement(_emo);
        this._emoHolder.setContent($(this.IDofEmoHolder));
        this._emoHolder.frame.style.zIndex = 9000;
        this._emoHolder.hide();
        $(this.IDofEmoHolder).show();
        this._emoRendered = true;
        XN.log('emotion render ok');
        //$(this.IDofEmoList).appendHTML(html);
    },
    
    //解析表情点击事件
    parseEmotion:function(e)
    {
        var img = XN.event.element(e), This = this;
        if(img.tagName.toLowerCase() == 'li') img = img.getElementsByTagName('img')[0];
        if(img && img.tagName.toLowerCase() == 'img')
        {
            var forvip = ( img.getAttribute('forvip') === 'true' ),
                ubb = img.getAttribute('emotion'),
                isVip = This.isVip;
            if(forvip && !isVip)
            {
                This.showNotVip(e);
            }
            else This.addEmotion(ubb);
        }
    },

    //将表情ubb添加至textarea
    addEmotion:function(code)
    {
        if(!this._inputHelper) this._inputHelper = new XN.FORM.inputHelper($(this.IDofTextarea));
        var input = $(this.IDofTextarea);
        //this.getInputPos();
        

        var pos = this._inputPos;
        var This = this;
        if(this.ubbPrefix) code = this.ubbPrefix + code;
        if(this.ubbSuffix) code += this.ubbSuffix;
        
        //防止dafaultValue
        var _trueValue = XN.form.help(input).getRealValue(); 
        if( _trueValue == '' ) XN.form.help(input).focus();

        setTimeout(function()
        {

            input.value = _trueValue.slice(0, pos.start) + code + _trueValue.slice(pos.end);//将这句移到setTimeout内, 让表情的插入在focus之后, 这样inputHelper就有足够的时间将默认文本设置为'' by huihua.lin@opi-corp.com 2010-1-22
            //This._inputHelper.focus(pos.start + code.length);
            XN.form.help(input).focus(pos.start + code.length);
            This.getInputPos();
        } , 10 );
    },
    
    //非vip用户提示
    showNotVip:function(e)
    {
        //XN.Do.alert('你不是vip');
        $(this.IDofEmoList).hide();
        $(this.IDofNotVipTip).show();
        if(this._previewHolder) this._previewHolder.hide();
        XN.event.stop(e || window.event);
    }, 
    //隐藏非vip提示
    hideNotVip:function(e)
    {
        //XN.Do.alert('你不是vip');
        $(this.IDofNotVipTip).hide();
        $(this.IDofEmoList).show();
    },
    
    //大表情预览
    previewEmotion:function(e)
    {
        img = XN.event.element(e);
        var This = this;
        if(img.tagName.toLowerCase() == 'a') img = img.getElementsByTagName('img')[0];
        if(img && img.tagName.toLowerCase() == 'img')
        {
            var showPreview = img.getAttribute('preview');
            if(showPreview)
            {
                if(!this._previewHolder)
                {   
                    var _fix = {
                        alignWith : this.IDofEmoList,
                        tagName : 'div',
                        alignType : '2-2',
                        offsetX : ( XN.browser.IE6 ? -1 : ( XN.browser.IE ? 1 : 0 ) ),
                        offsetY : ( XN.browser.IE ? 1 : 0 )
                    }
                    
                    this._previewHolder = new XN.ui.fixPositionElement(_fix);
                    this._previewHolder.container.setStyle('background:#fff;padding:1px;width:50px;height:50px;border:1px solid #B8D4E8;');
                    this._previewHolder.container.className = 'meditor-emo-preview';
                    this._previewHolder.container.id = 'mEditorPreviewHolder';
                    this._previewHolder.setContent('<img id="previewIMG" class="m-editor-preview-img" src="' + img.src + '" />');
                    
                    XN.event.addEvent($('mEditorPreviewHolder'),'mouseover',function()
                        {
                            var alignType = This._previewHolder.alignType == '1-1' ? '2-2' : '1-1';
                            if(XN.browser.IE6)
                            {
                                var offsetX = This._previewHolder.alignType == '1-1' ? -1 : 1;
                                This._previewHolder.setOffsetX(offsetX);
                            }
                            This._previewHolder.setAlignType(alignType);
                            
                        }
                    )
                }
                this._previewHolder.hide();
                $('previewIMG').src = img.src;
                this._previewHolder.show();
            }
        }
    },
    
    //隐藏表情预览
    hidePreviewEmotion:function(e)
    {
        el = XN.event.element(e);
        if(el.tagName.toLowerCase() == 'ul' && this._previewHolder) this._previewHolder.hide();
    },
    
    //添加链接弹层
    showAddLinkFlyer:function()
    {
        //this.getInputPos();
        var This = this, pos = this._inputPos, _style = '';
        if(pos.start != pos.end) _style="display:none";
        var html = 
            '<div style="text-align:center;">' +
                '<label style="display:block;margin:5px 0;">网址：<input type="text" class="input-text" id="mEditorUrl" style="width:230px;" /></label>' +
                '<label style="display:block;margin:5px 0;' + _style + '">文字：<input type="text" class="input-text" id="mEditorTxt" style="width:230px;" /></label>' +
            '</div>';
        XN.DO.confirm({
            msg:html,
            title:'添加链接',
            yes:'添加',
            callBack:function(y)
            {
                if(y) This.addLink();
            }
        });
    },
    
    //将链接添加至textarea
    addLink:function()
    {
        var _url = $('mEditorUrl').value,
            _txt = '',
            input = $(this.IDofTextarea),
            pos = this._inputPos,
            This = this;
        if(!_url) return;
        if(!this._inputHelper) this._inputHelper = new XN.FORM.inputHelper($(this.IDofTextarea));

        if(pos.start != pos.end)
        {
            _txt = input.value.slice(pos.start,pos.end);
        }
        else
        {
            _txt = $('mEditorTxt').value;
            if(!_txt) _txt = _url;
        }

        if(!/^(http:\/\/|https:\/\/)/.test(_url)) _url = 'http://' + _url;
        var code = '[url=' + encodeURI(_url) +']' + _txt + '[/url]'; 
        input.value = input.value.slice(0, pos.start) + code + input.value.slice(pos.end);
        input.blur();
        setTimeout(function()
        {  
            This._inputHelper.focus(pos.start + code.length);
            This.getInputPos();
        } , 10 );
    },

	renderUploadPhoto:function() {
		var btn = $(this.IDofUploadBtn);
		if (!btn) return;
		if (!window.SWFUpload) return;
		var buttonWrapper = $(this.IDofUploadBtn).parentNode;
		var This = this;
		var uploader = new SWFUpload({
			upload_url: 'http://upload.' + XN.env.domain + '/uploadservice.fcgi?pagetype=gossipAddPhoto&societyguester='+XN.cookie.get("societyguester")+'&hostid='+XN.cookie.get("id")+'&t='+XN.cookie.get('t'),
			flash_url: 'http://s.xnimg.cn/jspro/swfupload.v2.2.0.1/swfupload.swf',
			file_size_limit : "10 MB",
			file_types : "*.jpg;*.jpeg;*.png;*.bmp;*.gif",
			file_types_description : "All Image Files",
			file_upload_limit : 60,
			file_queue_limit : 0,
			debug: false,

			// Button Settings
			button_placeholder_id : this.IDofUploadBtn,
			button_cursor : SWFUpload.CURSOR.HAND,
			button_width: 28,
			button_height: 23,
			button_image_url: "http://a.xnimg.cn/a.gif",
			button_text: '<span class="text">图片</span>',
			button_text_style: '.text {text-align:left;color:#005EAC;font-family:tahoma,simsun;font-size:12px;font-family:Tahoma,Verdana,simsun,sans-serif;}',
			button_text_top_padding: 2,
			button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
			button_cursor : SWFUpload.CURSOR.HAND,
			button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,

			file_queued_handler: function() {
				try {
					uploader.setButtonDimensions(0, 0);
				} catch (e) {
					XN.DO.showError('对不起，你的浏览器暂时不支持此功能，请更换浏览器。');
				}
				this.startUpload();
			},
			upload_error_handler: function(file, code, message) {
				XN.DO.showError(message + "" + code + "" + file);
			},
			upload_progress_handler: function(file, bytes, total) {
				$('miniEditorPhotoInfo').show();
				$('miniEditorPhotoInfo').innerHTML = '正在添加... ' + parseInt(bytes/total*100) + '%';
			},
			upload_success_handler: function(file, r) {
				var uploader = this;
				function restoreUpload() {
					$('emoBtn').show();
					uploader.setButtonDimensions(28, 23);
					uploader.setButtonText('<span class="text">图片</span>')
					$($('miniEditorPhotoInfo').parentNode).delClass('attached');
					$('miniEditorDeletePhoto').hide();
					$('miniEditorPhotoInfo').hide();
					$('gossipLargeUrl').value = '';
					$('gossipHeadUrl').value = '';
					
					//这一句是邪恶的代码～要干掉
					if (window.commentPost) commentPost.hasPhoto = false;
					
					This.fireEvent('uploadDel');
					
				}
				var json = XN.json.parse(r);
				if (json.code != 1) {
					XN.DO.showError(json.msg);
					restoreUpload();
					return;
				}
				$('gossipLargeUrl').value = json.large;
				$('gossipHeadUrl').value = json.thumbnail;
				$('emoBtn').hide();
				function textEllipsis(str, length) {
					if (!length) length = 10;
					return str.length > length? (str.substr(0, length) + '...') : str;
				}
				$('miniEditorPhotoInfo').innerHTML = textEllipsis(file.name.substr(0, file.name.lastIndexOf('.')), 10) + file.type;
				$($('miniEditorPhotoInfo').parentNode).addClass('attached');
				$('miniEditorPhotoInfo').className = 'file-name';
				$('miniEditorPhotoInfo').show();
				$('miniEditorDeletePhoto').show();
				$('miniEditorDeletePhoto').onclick = restoreUpload;
				this.setButtonDimensions(0, 0);
				//这个代码实在是恶心...有机会把它干掉
				if (window.commentPost) {
					commentPost.afterPost = restoreUpload;
					commentPost.hasPhoto = true;
				}
				This.fireEvent('uploadSus',{
					restore : restoreUpload
				});
				
			}
		});
	},

	//记录textarea光标位置
	getInputPos:function()
	{
        var This = this;
		var textBox = $(This.IDofTextarea);
        var start = 0, end = 0;
        if ( typeof( textBox.selectionStart ) == 'number' )
        {
            start = textBox.selectionStart;
            end = textBox.selectionEnd;
            //alert(start + ':' + end);
        }
        else if ( document.selection )
        {
            var range = document.selection.createRange();
            //alert(range);
            if ( range.parentElement() == textBox )
            {
                var range_all = document.body.createTextRange();
                range_all.moveToElementText( textBox );
                for ( start=0; range_all.compareEndPoints( 'StartToStart' , range ) < 0; start++ )
                    range_all.moveStart( 'character', 1 );
                for ( var i = 0; i <= start; i ++ )
                {
                    if ( textBox.value.charAt(i) == '\n' )
                        start++;
                }
                
                var range_all = document.body.createTextRange();
                range_all.moveToElementText(textBox);
                
                for ( end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++ )
                    range_all.moveStart('character', 1);
                
                for ( var i = 0; i <= end; i ++ )
                {
                    if (textBox.value.charAt(i) == '\n')
                        end ++;
                }
            }
        }
        This._inputPos = {"start": start, "end": end, "item": [start, end]};
        //alert('pos is ' + start + ':' + end); 
        //XN.log(This._inputPos);
    }
})
XN.event.enableCustomEvent(XN.ui.miniEditor.prototype);

//------------
XN.ui.miniEditor.colorTip = [
    '<div class="color-palette clearfix">',
        '<div class="float-left">',
            //'<img src="http://hdn211.xnimg.cn/photos/hdn211/20090806/1010/tiny_9VKi_33490d204235.jpg" height="65" width="65">',
            '<img src="http://a.xnimg.cn/imgpro/icons/grade/csly.png" height="65" width="65">',
            '<span>彩色留言</span>',
        '</div>',
        '<p>对不起，该功能需要<span>等级7级以上</span>或者<span>VIP用户</span>才可以使用。</p>',
        '<p><a href="http://www.'+ XN.env.domain +'/scores/myscore" target="_blank" class="behavior btn_level">查看我的等级</a> 或 <a href="http://i.'+ XN.env.domain +'/pay/pre?wc=370000 " class="btn_vip" target="_blank">升级VIP</a></p>',
    '</div>',
].join('');













